let form = layui.form;

form.verify({
    len: [/^\S{6,12}$/, '长度必须6~12位不能出现空格'],
    
    diff: function (val) {
        if ($('input').eq(0).val() === val) {
            return '新密码不能和原密码一致'
        }
    },
    same: function (val) {
        if (val !== $('input').eq(1).val()) {
            return '两次新密码不一致';
        }
    }
});
$('form').on('submit', function (e) {
    e.preventDefault();
    $.ajax({
        type: 'POST',
        url: '/my/user/updatepwd',
        data: $(this).serialize(),
        success: function (res) {
            layer.msg(res.message);
            if (res.status === 0) {
                localStorage.removeItem('token');
                // 让父页面跳转
                window.parent.location.href = '../login.html';
            }
        }
    })
})
